"""
Case Type   : USTORE
Case Name   : 验证参数ustore_attr(ustats_tracker_naptime)设置
Create At   : 2025/3/25
Owner       : wan005
Description :
    1.查询参数默认值
    2.修改值为ustats_tracker_naptime=1
    3.修改值为ustats_tracker_naptime=2147483.647
    4.修改值为ustats_tracker_naptime=20
Expect      :
    1.参数默认值ustore_verify_level=FAST;ustore_verify_module=UPAGE:UBTREE
    2.修改成功
    3.修改成功
    4.修改成功
History     :
"""
import os
import unittest
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant


class Security(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'---{os.path.basename(__file__)} start---')
        self.sh_primy = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common()
        self.default_params = \
            'ustore_verify_level=FAST;ustore_verify_module=UPAGE:UBTREE'

    def test_ustore(self):
        text = '-----step1:查询参数默认值;expect:成功-----'
        self.logger.info(text)
        res1 = self.common.show_param('ustore_attr')
        self.assertEqual(self.default_params, res1, text + '执行失败')

        text = 'step2:参数默认值ustats_tracker_naptime=1;expect:成功'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                        "ustore_attr='ustats_tracker_naptime=1'")
        res2 = self.common.show_param('ustore_attr')
        self.assertEqual('ustats_tracker_naptime=1', res2, text + '执行失败')

        text = '---step3:修改ustats_tracker_naptime=2147483.647;expect:成功---'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                        "ustore_attr='ustats_tracker_naptime=2147483.647'")
        res3 = self.common.show_param('ustore_attr')
        self.assertEqual('ustats_tracker_naptime=2147483.647', res3,
                         text + '执行失败')

        text = '---step4:修改ustats_tracker_naptime=20;expect:成功---'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                "ustore_attr='ustats_tracker_naptime=20'")
        res4 = self.common.show_param('ustore_attr')
        self.assertEqual('ustats_tracker_naptime=20', res4, text + '执行失败')

    def tearDown(self):
        text = '-----step1:清理环境，恢复配置;expect:成功-----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    f"ustore_attr='{self.default_params}'")
        res_show = self.common.show_param('ustore_attr')
        self.assertEqual(self.default_params, res_show, text + '执行失败')
        self.logger.info(f'---{os.path.basename(__file__)} end---')
